﻿using System;

using Moe.ECamel.Common.Entities;
using Moe.ECamel.Client.Controllers;
using Moe.ECamel.Client.WinForms.Common;

namespace Moe.ECamel.Client.WinForms.Controls
{
	public partial class UserDetailsControl : ECamelUserControl
	{
		public UserDetailsControl()
		{
			InitializeComponent();
		}

		private DetailsMode _detailsMode;
		public DetailsMode DetailsMode
		{
			get { return _detailsMode; }
			set
			{
				this._detailsMode = value;
				this.UsernameTextBox.ReadOnly = (value == DetailsMode.View);
				this.TitleTextBox.ReadOnly = (value == DetailsMode.View);
				this.FirstNameTextBox.ReadOnly = (value == DetailsMode.View);
				this.MiddleNameTextBox.ReadOnly = (value == DetailsMode.View);
				this.LastNameTextBox.ReadOnly = (value == DetailsMode.View);
				this.EmailTextBox.ReadOnly = (value == DetailsMode.View);
				this.TelephoneTextBox.ReadOnly = (value == DetailsMode.View);
				this.HomeAddressTextBox.ReadOnly = (value == DetailsMode.View);
			}
		}

		public void Bind(User entity)
		{
			UserBindingSource.DataSource = entity;
			UserIdTextBox.Bind(UserBindingSource, "UserId");
			UsernameTextBox.Bind(UserBindingSource, "Username");
			TitleTextBox.Bind(UserBindingSource, "Title");
			FirstNameTextBox.Bind(UserBindingSource, "FirstName");
			MiddleNameTextBox.Bind(UserBindingSource, "MiddleName");
			LastNameTextBox.Bind(UserBindingSource, "LastName");
			TelephoneTextBox.Bind(UserBindingSource, "Telephone");
			HomeAddressTextBox.Bind(UserBindingSource, "HomeAddress");
			EmailTextBox.Bind(UserBindingSource, "EmailAddress");
		}
		public void CancelEdit()
		{
			this.UserBindingSource.CancelEdit();
		}
	}
}